﻿using WF_AppFuel.Validation.Attributes;
using WF_AppFuel.Validation.Base;

namespace WF_AppFuel.Validation.Engines
{
    /// <summary>
    /// This engine is used for validating required fields.
    /// </summary>
    /// <author>Arjay C. Nacion</author>
    public sealed class IsRequiredValidationEngine : BaseValidationEngine
    {
        public override bool Run()
        {
            IsRequired requiredAttribute = (IsRequired)ValidationAttribute;
            if (requiredAttribute.Required)
            {
                if (Value == null)
                    return false;

                if (Value is string)
                    if (string.IsNullOrEmpty(Value.ToString().Trim()))
                        return false;
            }

            return true;
        }
    }
}
